In [2]:
from sympy import init_session
init_session()


IPython console for SymPy 0.7.6 (Python 2.7.6-64-bit) (ground types: python)

These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
>>> init_printing()

Documentation can be found at http://www.sympy.org

In [3]:
p,mu,x,k = symbols('p,mu,x,k')

In [4]:
f = p * mu * (  ( (mu * x)** (k -2)) / factorial(k - 2) ) * exp(-mu*x) + (1 -p) * mu * ( ( (mu *x )** (k -1)) / factorial(k -1) ) * exp(-mu*x)

In [5]:
f


Out[5]:
$$\frac{\mu p \left(\mu x\right)^{k - 2}}{\left(k - 2\right)!} e^{- \mu x} + \frac{\mu \left(\mu x\right)^{k - 1}}{\left(k - 1\right)!} \left(- p + 1\right) e^{- \mu x}$$

In [6]:
F = integrate(f,x)

In [12]:
F


Out[12]:
$$\frac{k \left(- p + 1\right) \Gamma{\left(k \right)} \gamma\left(k, \mu x\right)}{\left(k - 1\right)! \Gamma{\left(k + 1 \right)}} + \frac{\mu p}{\left(k - 2\right)!} \left(\frac{k \Gamma{\left(k - 1 \right)}}{\mu \Gamma{\left(k \right)}} \gamma\left(k - 1, \mu x\right) - \frac{\Gamma{\left(k - 1 \right)}}{\mu \Gamma{\left(k \right)}} \gamma\left(k - 1, \mu x\right)\right)$$

Check if F is correct by deriving F, then subtract that from the original function


In [7]:
diff(F,x)


Out[7]:
$$\frac{k \mu \left(\mu x\right)^{k - 1} e^{- \mu x} \Gamma{\left(k \right)}}{\left(k - 1\right)! \Gamma{\left(k + 1 \right)}} \left(- p + 1\right) + \frac{\mu p}{\left(k - 2\right)!} \left(\frac{k e^{- \mu x}}{\Gamma{\left(k \right)}} \left(\mu x\right)^{k - 2} \Gamma{\left(k - 1 \right)} - \frac{\left(\mu x\right)^{k - 2}}{\Gamma{\left(k \right)}} e^{- \mu x} \Gamma{\left(k - 1 \right)}\right)$$

In [8]:
eq = diff(F,x) - f
simplify(eq)t


Out[8]:
$$0$$

In [9]:
simplify(F)


Out[9]:
$$\frac{k}{k!} \left(k p \gamma\left(k - 1, \mu x\right) - p \gamma\left(k, \mu x\right) - p \gamma\left(k - 1, \mu x\right) + \gamma\left(k, \mu x\right)\right)$$

In [ ]: